function [ bimg, bftKernel ] = my_box2DFFT( img, w )
%MY_BOX2DFFT Summary of this function goes here

sY = size(img,1);
sX = size(img,2);

%building up empty filter kernel and the image-sized version
boxKernel = zeros(w,w);
greaterKernel = zeros(sY,sX);

%fill the kernel with entries:
    %Inversion of the kernel size
boxKernel(:) = inv( double(w*w) );
    %create image-sized kernel out of the w sized
greaterKernel(1:w, 1:w) = boxKernel;


%apply fourier transformation on the image and the greater kernel version
fftImg = fft2(img);
fftKernel = fft2(greaterKernel);


%applying the filter to the image (= multiplication in fft is equivalent
%   to summation in time domain)
for i=1:3,
    fftImg(:,:,i) = fftImg(:,:,i).*fftKernel;
end

%return the fft version of the filter kernel
%   and the image in time domain
bftKernel = fft2(boxKernel); 
bimg = ifft2(fftImg);

end

